home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
bbsutil
/
hsrc_117.zip
/
EDITOR.C
< prev
next >
Wrap
Text File
|
1990-11-08
|
27KB
|
1,285 lines
/* Editor.C File */
#include "msgg.h"
#include "twindow.h"
#include "headedit.h"
#include "keys.h"
extern void pascal dcls(void);
extern void pascal dputc(int x, int y, int c);
extern int pascal dputs(int x, int y, char *s);
extern void pascal dclrwnd(int x1, int y1, int x2, int y2);
extern void pascal dscrollup(int x1, int y1, int x2, int y2);
extern void pascal dscrolldn(int x1, int y1, int x2, int y2);
extern word vbase;
extern word maxx;
extern word maxy;
extern char current_color;
extern word videomethod;
#define TRUE 1
#define FALSE 0
#define TABS 4
#define NEXTTAB (TABS-(x%TABS))
#define LASTTAB (((wwd-1)/TABS)*TABS)
#define PREVTAB (((x-1)%TABS)+1)
#define curr(x,y) (bfptr+(y)*wwd+(x))
#define lineno(y) ((int)(bfptr-topptr)/wwd+(y))
#define sayline(y) ((unsigned int)((unsigned int)bfptr-(unsigned int)topptr)/(unsigned int)wwd+((unsigned int)y))
extern int VSG;
int last_x,last_y;
static char qstr[7];
char keybuf[256]="";
static int quoting=0;
static int wht;
static int wwd;
static int wsz;
static char *topptr;
static char *bfptr;
static char *lstptr;
static int lines;
static char *endptr;
static int blkbeg;
static int blkend;
static int inserting;
static WINDOW *wnd;
static int do_display_text=1;
char abortedit;
/* Local function prototypes */
extern int pascal do_macro (int c);
extern char * pascal get_string (char *text,char len,char *deflt,char type);
extern char pascal ask_question (char *text);
void pascal file_funcs(int y,int command);
void pascal save_text(int justblk,int append);
void pascal load_text(int y,int insertit);
void pascal unquote(int *x,int *y);
void pascal quote_mark (int x,int y);
void pascal erase_buffer(int *x,int *y);
char pascal ask_quit(void);
char pascal ask_save(void);
int pascal lastword(int x,int y);
void pascal last_char(int *x,int *y);
void pascal test_para(int x,int y);
int pascal trailing_spaces(int y);
int pascal first_wordlen(int y);
void pascal paraform(int x,int y,char);
int pascal blankline(int line);
void pascal delete_word(int x,int y);
void pascal delete_line(int y);
void pascal delete_block(void);
void pascal copy_block(int y);
void pascal move_block(int y);
void pascal mvblock(int y,int moving);
void pascal findlast(void);
void pascal find_end(int *x,int *y);
void pascal carrtn(int *x,int *y,int insert);
void pascal backspace(int *x,int *y);
void pascal fore_word(int *x,int *y,char *bf);
int pascal spaceup(int *x,int *y,char **bf);
void pascal back_word(int *x,int *y,char *bf);
int pascal spacedn(int *x,int *y,char **bf);
void pascal forward(int *x,int *y);
int pascal downward(int *y);
void pascal upward(int *y);
void pascal display_text(void);
void pascal disp_line(int y);
void pascal insert_line(void);
extern char notefile[133];
/* Process text entry for a window */
char * pascal text_editor (WINDOW *wnd1,char *bf,unsigned int bsize) {
char lastun;
char *b,*buff,*pp;
int depart=FALSE,i,c;
int x,y,svx,svlw,tx,tabctr=0;
memset(qstr,0,6); /* Build quote string */
*qstr=' ';
if(*msg.to) {
qstr[1]=*msg.to;
pp=strchr(msg.to,' ');
if(pp && pp[1]) qstr[2]=pp[1];
}
strcat(qstr,"> ");
abortedit=0;
wnd=wnd1;
wht=HEIGHT-2;
wwd=WIDTH-2;
wsz=wwd*wht;
topptr=bfptr=bf;
lines=bsize/wwd;
endptr=bf+wwd*lines;
blkbeg=0;
blkend=0;
inserting=TRUE;
x=(maxx-1)-strlen(notefile);
if(x<49)x=49;
current_color=readtextcolor + (readtextback * 16);
lowvideo();
dprintf(x,6,"%0.28s",notefile);
x=y=0;
memset(bf,' ',bsize);
load_text(0,0); /* Initial load */
display_text();
while (TRUE) {
last_x=COL+1+x;
last_y=ROW+1+y;
if(last_y>(maxy-1)) {
last_y--;
y--;
}
cursor(last_x,last_y);
buff=curr(x,y);
if (tabctr) {
--tabctr;
c=' ';
}
else {
if(*keybuf) {
c=*keybuf;
memmove(keybuf,&keybuf[1],strlen(&keybuf[1])+1);
}
else if (quoting) quote_mark(x,y);
else {
current_color=readtextcolor + (readtextback * 16);
lowvideo();
dprintf(3,6,"%3u | %-3u",x+1,sayline(y)+1);
c=get_char();
}
clear_message();
}
switch(c) {
case CTRL_W: /* Wrap on/off */
if(!stricmp(notefile,"MSGTMP")) {
wrapit=1-wrapit;
if(wrapit) any_message(" Wrap at save off ");
else any_message(" Wrap at save on ");
pause();
}
break;
case CTRL_O: /* Origin toggle */
if(!stricmp(notefile,"MSGTMP")) {
usedefault=1-usedefault;
if(usedefault) {
get_origin();
}
else {
any_message(" Looking up Origin line in ORIGINS.BBS ");
pause();
}
}
break;
case ALT_F1: /* Spawn keys */
case ALT_F2:
case ALT_F3:
case ALT_F4:
case ALT_F5:
case ALT_F6:
case ALT_F7:
case ALT_F8:
case ALT_F9:
case ALT_F10:
do_spawn(convertstring(fkey[c-ALT_F1]));
break;
case ALT_M: /* Macros */
set_help("macrohelp ",0,0);
any_message(" Press macro key: ");
c=get_char();
set_help("edithelp ",0,0);
clear_message();
if(!do_macro(c)) {
if(c!=ESC) {
error_message(" Undefined macro key ");
pause();
}
}
break;
case ALT_P: /* Literal */
any_message(" Press literal key: ");
set_help("lithelp ",0,0);
c=get_char();
set_help("edithelp ",0,0);
clear_message();
goto LiteralBreakIn;
case ALT_R: /* Read block */
file_funcs(y,4);
break;
case ALT_W: /* Write block */
file_funcs(y,5);
break;
case ALT_L: /* Load new file */
file_funcs(y,2);
break;
case ALT_S: /* Save file */
file_funcs(y,1);
break;
case ALT_C: /* Change filename */
file_funcs(y,3);
break;
case ALT_F: /* File functions */
file_funcs(y,0);
break;
case CTRL_E: /* Edit header */
if(!stricmp(notefile,"MSGTMP")) {
edit_mess(2);
show_header(0);
}
break;
case CTRL_U: /* Unquote text */
if(blankline(lineno(y)+1)) if (!blankline(lineno(y+1)+1)) downward(&y);
unquote(&x,&y);
break;
case ALT_Q: /* Set quote string */
memset(qstr,0,6); /* Build quote string */
*qstr=' ';
if(*msg.to) {
qstr[1]=*msg.to;
pp=strchr(msg.to,' ');
if(pp && pp[1]) qstr[2]=pp[1];
}
strcat(qstr,"> ");
set_help("quotshelp ",0,0);
pp=get_string("Enter quote string:",6,qstr,'a');
if(*pp) {
strcpy(qstr,pp);
if(strlen(qstr)<6 && qstr[strlen(qstr)-1]!=' ') strcat(qstr," ");
}
set_help("edithelp ",0,0);
break;
case CTRL_Q: /* Quote text */
if(blankline(lineno(y)+1)) if (!blankline(lineno(y+1)+1)) downward(&y);
quote_mark(x,y);
break;
case '\r': /* CR */
carrtn(&x,&y,inserting);
break;
case DN: /* Down */
downward(&y);
break;
case PGUP: /* Page Up */
y=0;
for(i=0;i<wht;i++) upward(&y);
x=0;
break;
case PGDN: /* Page Down */
y=HEIGHT-2;
for(i=0;i<wht;i++)
downward(&y);
y=0;
break;
case '\t': /* Tab */
if (x + NEXTTAB < wwd) {
if (inserting)
tabctr=NEXTTAB;
else
x+=NEXTTAB;
}
else
carrtn(&x,&y,inserting);
break;
case SHIFT_HT: /* Shift-tab */
if (x<TABS) {
upward(&y);
x=LASTTAB;
}
else
x-=PREVTAB;
break;
case CTRL_FWD: /* CTRL-=> */
fore_word(&x,&y,buff);
break;
case CTRL_BS: /* CTRL-<= */
back_word(&x,&y,buff);
break;
case CTRL_PGUP: /* Top of paragraph */
while(curr(0,y)>topptr) {
upward(&y);
if(blankline(lineno(y)+1)) break;
}
break;
case CTRL_PGDN:
while(curr(0,y)<endptr) {
downward(&y);
if(blankline(lineno(y)+1)) break;
}
break;
case CTRL_B: /* Bottom of page */
y=wht-1;
last_char (&x,&y);
break;
case CTRL_T: /* Top of page */
x=y=0;
break;
case CTRL_HOME: /* Top of file */
x=y=0;
bfptr=topptr;
display_text();
break;
case HOME: /* Start of line */
x=0;
break;
case CTRL_END: /* End of file */
find_end(&x,&y);
last_char (&x,&y);
display_text();
break;
case END: /* End of line */
last_char (&x,&y);
break;
case UP: /* up-arrow */
upward(&y);
break;
case CTRL_A: /* Abort; no sav